package org.dromara.netbar.service.impl;

import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.constant.NetbarConstants;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.redis.utils.RedisUtils;
import org.dromara.system.service.ISysConfigService;
import org.springframework.stereotype.Service;

/**
 * @author ZhouWenTao
 * @create 2025-08-14 21:09
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class NetbarCommonService {
    @Resource
    private ISysConfigService sysConfigService;

    /**
     * 获取门店名称
     * @param tenantId 租户id
     * @return 门店名称
     */
    public String getStoreName(String tenantId){
        if (StringUtils.isEmpty(tenantId)) {
            return "未知";
        }
        String storeName = RedisUtils.getCacheMapValue(tenantId + ":" + CacheNames.SYS_CONFIG, NetbarConstants.NETBAR_STORE_NAME_KEY);
        if(null == storeName){
            // 查询数据库
            storeName = sysConfigService.selectConfigByKey(NetbarConstants.NETBAR_STORE_NAME_KEY);
        }
        return ((null == storeName) ? "未知" : storeName);
    }
}
